<!--
    报警警情
 * @Author: zhanbh
 * @Date: 2021-04-08 10:46:41
 * @project: 天津YQ平台
-->
<template>
  <div class="info-110">
    <el-form ref="form" label-width="80px">
      <div class="table-filter table-filter-home">
        <div>
          <el-form-item label="发布时间:">
            <el-date-picker
              v-model="publishTime"
              clearable
              type="datetimerange"
              value-format="yyyyMMddHHmm"
              format="yyyy-MM-dd HH:mm"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00']"
            />
          </el-form-item>
        </div>
        <div>
          <el-form-item label="发布单位:">
            <dg-tree-drop
                 v-model="fbdwdm"
                 :code="BM_DEPT"
                 :check-strictly="true"
                 :props="props" lazy-load
                 filterable clearable
                 value-name="value"
                 label-name="label"
                 style="width: 100%"
                 multiple
                 collapse-tags
                 :cacheable="true"
            ></dg-tree-drop>
            <!-- <el-cascader v-model="fbdwdm" :options="constant.BM_DEPT" :show-all-levels="false" clearable/> -->
          </el-form-item>
        </div>
        <div>
          <el-form-item label="最晚反馈时间:" label-width="120px">
            <el-date-picker
              v-model="time"
              clearable
              type="datetimerange"
              value-format="yyyyMMddHHmm"
              format="yyyy-MM-dd HH:mm"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00']"
            />
          </el-form-item>
        </div>
        <div>
          <el-form-item label="接收单位:">
                <dg-tree-drop
                 v-model="jsdwdm"
                 :code="BM_DEPT"
                 :check-strictly="true"
                 :props="props" lazy-load
                 filterable clearable
                 value-name="value"
                 label-name="label"
                 style="width: 100%"
                 multiple
                 collapse-tags
                 :cacheable="true"
            ></dg-tree-drop>
             <!-- <el-cascader v-model="jsdwdm" :options="constant.BM_DEPT" :show-all-levels="false" clearable/> -->
          </el-form-item>
        </div>
        <div>
          <el-form-item label="关键词:">
            <el-input v-model="condition.keys.value" placeholder="报警内容、标题" clearable />
          </el-form-item>
        </div>
        <div>
          <el-form-item class="operate-btns">
            <el-button type="primary" size="mini" @click="() => $refs.table.searchForm()"> 查询 </el-button>
            <el-button size="mini" @click="reset">重置</el-button>
          </el-form-item>
        </div>
      </div>
    </el-form>
    <div class="info-110__list">
      <comm-table ref="table" :condition="condition" :columns="columns" url="/v1/zl/search" :pageSize="pageSize"> </comm-table>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { deepClone } from '@/utils/common';
import { BM_DEPT } from '@/common/codeDic';
export default {
  name: 'PoliceOrderHome',
  data() {
    return {
      BM_DEPT,
      publishTime: [],
      time: [],
      fbdwdm:[],
      jsdwdm:[],
      cloneCondition: null,
      active: '',
      columns: [
        { label: '序号', type: 'index' },
        { label: '发布时间', prop: 'fbsj' },
        { label: '发布单位', prop: 'fbdwdm', code: BM_DEPT },
        {
          label: '关联警情',
          prop: 'title',
          render: (h, row) => {
            const _this = this;
            if(row.glxx){
            return h(
              'div',
              {
                class: 'v-link',
                on: {
                  click() {
                    // 隐藏tooltip(由于不自动消失)
                    $('.el-tooltip__popper').css('display', 'none');
                    _this.$router.push({ name: 'PoliceOrderDetail', params: { id: row.flowid } });
                  }
                }
              },
              row.glxx
            );
            }else{
              return h(
                'span',
                '-'
              )
            }
          }
        },
        { label: '最晚反馈时间', prop: 'zwfksj' },
        {
          label: '接收单位',
          prop: 'jsdwdmList',
          render: (h, row) => {
            const _this = this;
            const findLabel = (v) => {
              return _this.constant.BM_DEPT.find((item) => item.value === v);
            };
            return h('div', {}, [
              ...row.zljsList.map((item) => {
                return h(
                  'div',
                  {
                    class: _this.active === item.id && item.fkzt === '0' ? 'noFeedback' : '',
                    style: {
                      cursor: 'pointer'
                    },
                    on: {
                      mouseover() {
                        _this.active = item.id;
                      },
                      mouseout() {
                        _this.active = '';
                      }
                    }
                  },
                  findLabel(item.jsdwdm) ? findLabel(item.jsdwdm).label : '-' // 判空
                );
              })
            ]);
          }
        }
      ],
      pageSize: 10,
      condition: {
        zlly: {
          value: '2',
          op: '='
        },
        jsdwdm: {
          value: '',
          op: '='
        },
        keys: {
          value: '',
          op: '='
        },
        fksj: {
          value: '',
          op: '='
        },
        fbdwdm: {
          value: '',
          op: '='
        },
        fbsj: {
          value: '',
          op: '='
        },
        query_zljsxx: {
          value: true,
          op: '='
        }
      },
        props: {
           value: "value"
            },
    };
  },
  computed: {
    ...mapState(['constant'])
  },
  activated() {
    this.$refs.table.searchForm();
  },
  watch: {
    fbdwdm(val) {
      this.condition.fbdwdm.value = val.length ? val : '';
    },
    jsdwdm(val){
      this.condition.jsdwdm.value = val.length ? val : '';
    },
    time(val) {
      this.condition.fksj.value = val ? `${val[0]},${val[1]}` : '';
    },
    publishTime(val) {
      this.condition.fbsj.value = val ? `${val[0]},${val[1]}` : '';
    }
  },
  mounted() {
    this.$store.dispatch('getConstantTree', ['BM_DEPT']);
    this.cloneCondition = deepClone(this.condition);
  },
  methods: {
    reset() {
      this.time = null;
      this.fbdwdm=[]
      this.jsdwdm=[]
      this.publishTime = null;
      this.condition = deepClone(this.cloneCondition);
      this.$nextTick(() => {
        this.$refs.table.searchForm();
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.info-110 {
  /deep/.el-table__row {
    .noFeedback {
      color: red !important;
    }
  }
  display: flex;
  flex-direction: column;
  height: calc(100vh - 11rem);
  overflow: hidden;
  .check-box {
    display: flex;
    /deep/.checkbox-group {
      text-align: left;
    }
    /deep/ .el-checkbox {
      margin-right: 6px;
    }
  }
  &__list {
    flex-shrink: 1;
    flex-grow: 1;
    margin-top: 10px;
    background-color: #fff;
    padding: 1.5rem 2rem;
    overflow: auto;
  }
}
</style>
